
<template>
  <a-form class="smart-query-form">
    <a-row class="smart-query-form-row">
      <a-form-item label="姓名" class="smart-query-form-item" v-privilege="'system:sign:queryPage'">
        <a-input style="width: 300px" v-model:value="queryForm.actualName" placeholder="请输入姓名" />
        <!-- <a-select
          v-model:value="queryForm.registerSchool"
          show-search
          style="width: 300px"
          placeholder="请输入编号"
          :options="schooleOptions"
          :filterOption="filterOption"
        >
        </a-select> -->
      </a-form-item>

      <a-form-item class="smart-query-form-item smart-margin-left10">
        <a-button-group>
          <a-button type="primary" @click="onSearch" v-privilege="'system:sign:queryPage'">
            <template #icon>
              <SearchOutlined />
            </template>
            查询
          </a-button>
          <a-button @click="resetQuery" v-privilege="'system:sign:queryPage'">
            <template #icon>
              <ReloadOutlined />
            </template>
            重置
          </a-button>
          <a-button type="primary" @click="downloadFile"> 下载 </a-button>
          <!-- <a-button type="primary" @click="downloadFile2"> 下载附件 </a-button> -->
        </a-button-group>
      </a-form-item>
    </a-row>
  </a-form>

  <a-card size="small" :bordered="false" :hoverable="true">
    <a-row class="smart-table-btn-block">
      <div class="smart-table-operate-block"></div>
      <div class="smart-table-setting-block">
        <TableOperator v-model="columns" :tableId="TABLE_ID_CONST.TEACHERTION.REGISTRATIONrEVIEW" :refresh="ajaxQuery" />
      </div>
    </a-row>

    <a-table
      :scroll="{ x: 1300 }"
      size="small"
      :dataSource="tableData"
      :columns="columns"
      rowKey="employeeId"
      :pagination="false"
      :loading="tableLoading"
      bordered
    >
      
      <template #bodyCell="{ column, record, text }">
        <!-- <template v-if="column.dataIndex === 'political'">
                  :row-selection="{ selectedRowKeys: selectedRowKeyList, onChange: onSelectChange }"
                      {{ politicalList[record.political] }}
                  </template>
          <template v-if="column.dataIndex === 'marital'">
  
                      {{ maritalList[record.marital] }}
                  </template> -->
        <template v-if="column.dataIndex === 'gender'">
          {{ record.gender == 1 ? '男' : '女' }}
        </template>
        <template v-if="column.dataIndex === 'juniorHighSchool'">
          {{ formatSchoolName(record.juniorHighSchool) }}
        </template>
        <template v-if="column.dataIndex === 'ethnicGroupId'">
          {{ ethnicGroupList[record.ethnicGroupId - 1] }}
        </template>
        <!-- <template v-if="column.dataIndex === 'registerType'">
  
                      {{ registerTypeList[record.registerType] }}
                  </template> -->

        <template v-if="column.dataIndex === 'action'">
          <div class="smart-table-operate">
            <!-- <a-button v-if="record.isPass === 0" @click="examine(record.employeeId)" size="small" 
                              type="link">审核</a-button> -->
            <a-button @click="detail(record.employeeId)" size="small" type="link">详情</a-button>
          </div>
        </template>
      </template>
    </a-table>

    <div class="smart-query-table-page">
      <a-pagination
        showSizeChanger
        showQuickJumper
        show-less-items
        :pageSizeOptions="PAGE_SIZE_OPTIONS"
        :defaultPageSize="queryForm.pageSize"
        v-model:current="queryForm.pageNum"
        v-model:pageSize="queryForm.pageSize"
        :total="total"
        @change="ajaxQuery"
        @showSizeChange="ajaxQuery"
        :show-total="(total) => `共${total}条`"
      />
    </div>
    <!-- <EnterpriseOperate ref="operateRef" @refresh="ajaxQuery" /> -->
  </a-card>
  <DetailForm ref="detailFormRef"></DetailForm>
</template>
  <script setup>
import { reactive, ref, onMounted } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { registrationReviewApi } from '/@/api/registrationReview/index';
import { PAGE_SIZE, PAGE_SIZE_OPTIONS } from '/@/constants/common-const';
import { smartSentry } from '/@/lib/smart-sentry';
import TableOperator from '/@/components/support/table-operator/index.vue';
import { TABLE_ID_CONST } from '/@/constants/support/table-id-const';
import DetailForm from './components/index.vue';
import { loginApi } from '/@/api/system/login-api';
import { useUserStore } from '/@/store/modules/system/user';

// 选择表格行
const selectedRowKeyList = ref([]);
//岗位代码
const jobCodeList = ['教师岗位', '其他专业技术岗位', '管理岗位', '工勤技能岗位', '特设岗位', '无其他岗位'];
// 政治面貌
const politicalList = ['中共党员', '中共预备党员', '共青团员', '群众', '其他政治面貌'];
// 婚姻状况
const maritalList = ['未婚', '已婚', '离异', '丧偶'];
// 英语等级
const englishList = ['一级', '二级', '三级', '四级', '五级', '六级', '七级', '八级', '九级'];
// 普通话等级
const mandarinList = ['一级甲等', '一级乙等', '二级甲等', '二级乙等', '三级甲等', '三级乙等'];
// 教师资格证类别
const teacherCardTypeList = [
  '幼儿园教师资格',
  '小学教师资格',
  '初级中学教师资格 ',
  '高级中学教师资格',
  '中等职业学校教师资格',
  '中等职业学校实习指导教师资格',
  '高等学校教师资格',
];
// 教师资格证学科
const SubjectList = ['幼儿园', '小学', '初中', '高中'];
//学位
const academicDegreeList = ['学士', '硕士', '博士'];
// 学历
const educationList = ['本科', '硕士研究生', '博士研究生'];
const ethnicGroupList = ref([]);
const registerTypeList = ref([]);
// --------------------------- 企业表格 列 ---------------------------

const columns = ref([
  {
    title: '中考报名号',
    dataIndex: 'registerNum',
    width: 120,
  },

  {
    title: '姓名',
    dataIndex: 'actualName',
    width: 80,
    ellipsis: true,
  },
  {
    title: '性别',
    dataIndex: 'gender',
    width: 70,
    ellipsis: true,
  },
  {
    title: '初中学校',
    dataIndex: 'juniorHighSchool',
    width: 120,
  },
  {
    title: '手机号码',
    dataIndex: 'phone',
    width: 110,
  },
  {
    title: '邮箱',
    dataIndex: 'email',
    width: 150,
  },
  {
    title: '班级职务',
    dataIndex: 'position',
    width: 80,
  },
  {
    title: '户籍所在地',
    width: 160,
    dataIndex: 'houseLocation',
  },
  {
    title: '政治面貌',
    dataIndex: 'political',
    width: 110,
  },
  {
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
    width: 60,
  },
]);

// --------------------------- 查询 ---------------------------
const queryFormState = {
  // registerschool: '',
  actualName: null,
  pageNum: 1,
  pageSize: PAGE_SIZE,
  searchCount: true,
  // registerSchool: useUserStore().registerSchool,
};
const queryForm = reactive({ ...queryFormState });
const tableLoading = ref(false);
const tableData = ref([]);
const total = ref(0);

const filterOption = (input, option) => {
  return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
};

function onSearch() {
  queryForm.pageNum = 1;
  ajaxQuery();
}

function resetQuery() {
  queryForm.actualName = '';
  Object.assign(queryForm, queryFormState);
  ajaxQuery();
}

async function ajaxQuery() {
  try {
    tableLoading.value = true;
    let responseModel = await registrationReviewApi.queryPage(queryForm);
    const list = responseModel.data.list;
    total.value = responseModel.data.total;
    tableData.value = list;
  } catch (e) {
    smartSentry.captureError(e);
  } finally {
    tableLoading.value = false;
  }
}

function formatSchoolName(originalStr) {
  if (originalStr) {
    const parts = originalStr.split(',');
  
    if (parts.length === 2) {
      return `${parts[0]}区${parts[1]}学校`;
    }
  }
  return originalStr;
}

// --------------------------- 增加、修改、详情 ---------------------------

const detailFormRef = ref(null);
function examine(enterpriseId) {
  // detailFormRef.value.showModal(enterpriseId);
  detailFormRef.value.showModal(enterpriseId, 'examine');
}

function detail(enterpriseId) {
  detailFormRef.value.showModal(enterpriseId);
}

async function downloadFile() {
   await registrationReviewApi.downloadFilexlsx();
  // axios({
  //     method: 'POST', // 对于文件下载，通常使用GET请求
  //     url: 'http://10.10.1.21:1024/signUp/download', // 替换为实际的ZIP文件下载URL
  //     responseType: 'blob', // 设置为blob以接收二进制数据
  //     data: {
  //         "registerSchool": "上海市崇明区新村小学",
  //         "isPass": 0
  //     }
  // }).then(res=>{
  //     console.log(res, res.headers)
  //     const url = window.URL.createObjectURL(new Blob([res.data], { type: res.headers['content-type'] }));
  //     const link = document.createElement('a');
  //     link.href = url;
  //     // link.setAttribute('download', 'filename.xlsx');
  //     document.body.appendChild(link);
  //     link.click();
  //     document.body.removeChild(link);
  //     URL.revokeObjectURL(url);
  // })

  // registrationReviewApi
  //   .downloadFilexlsx({
  //     employeeIds: selectedRowKeyList.value.length ? selectedRowKeyList.value : null,
  //     actualName: queryForm.actualName,
  //     isPass: 0,
  //   })
  //   .then((res) => {
  //     const url = window.URL.createObjectURL(new Blob([res.data], { type: res.headers['content-type'] }));
  //     const link = document.createElement('a');
  //     link.href = url;
  //     link.setAttribute('download', '艺术生报名信息');
  //     document.body.appendChild(link);
  //     link.click();
  //     document.body.removeChild(link);
  //     URL.revokeObjectURL(url);
  //   });
}
function downloadFile2() {
  registrationReviewApi
    .downloadFile2({
      employeeIds: selectedRowKeyList.value.length ? selectedRowKeyList.value : null,
      registerSchool: queryForm.registerSchool,
      isPass: 0,
    })
    .then((res) => {
      console.log(res, res.headers);
      const url = window.URL.createObjectURL(new Blob([res.data], { type: res.headers['content-type'] }));
      const link = document.createElement('a');
      link.href = url;
      link.setAttribute('download', '附件');
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
      URL.revokeObjectURL(url);
    });
}
const schooleOptions = ref([]);
// 表格选择
function onSelectChange(selectedRowKeys) {
  selectedRowKeyList.value = selectedRowKeys;
}
onMounted(async () => {
  ajaxQuery();
  const res = await loginApi.ethnicGroupSelect();
  ethnicGroupList.value = res.data.data.map((i) => {
    return i.ethnicGroupName;
  });

  // const registerType = await loginApi.schoolType();
  // registerTypeList.value = registerType.data.rows.map((i) => {
  //   return i.MC;
  // });

  const schooleList = await loginApi.schoolList();
  schooleOptions.value = schooleList.data.map((i) => {
    return { label: i.name, value: i.name };
  });
});
</script>
  